from websocket_server import WebsocketServer

def new_client(client, server):
	'''新的客户端连接提示'''
	msg = '新用户: {} 加入...'.format(client['id'])
	server.send_message_to_all(msg)

def client_left(client, server):
	msg = '用户: {} 离开了...'.format(client['id'])
	server.send_message_to_all(msg)

def message_received(client, server, message):
	msg = "用户(%d) 说: %s" % (client['id'], message)
	server.send_message_to_all(msg)



if __name__ == '__main__':
	server = WebsocketServer(9001, "0.0.0.0")
	server.set_fn_new_client(new_client)
	server.set_fn_client_left(client_left)
	server.set_fn_message_received(message_received)
	server.run_forever()